<?php


namespace Admin\Controller;
use Think\Controller;
class LoginController extends Controller {

    public function login(){


    	if (IS_POST) {
    		

			$username = I('post.username');

			$sql = "SELECT * from `user` WHERE `username` = '$username'";
			$user = M('user');
			$query = $user -> query($sql);

			if(md5(I('post.password'))==$query[0]['password']){
				//用户名
				$_SESSION['username']=$query[0]['username'];
				//用户id
				$_SESSION['id']=$query[0]['id'];
								
				$this->success('登陆成功！',U('Admin/Index/index'));
			}else{

				$error = "alert('您的密码有错，请重新输入')";

				$this->assign('username', $username);
				$this->assign('error', $error);
				$this->display();
			}			
		}else{
		
			$this->display();
			// var_dump(dfiujfiuhfodsaifhjfioasfoi);
		}
		// layout(false);
		// $this->display();
	}


	public function loginout(){
		session_unset();
		session_destroy();
		$this->success('',U('/Home/'),0);
	}

	private function check_verify($code, $id = ''){
    	//验证验证码
	    $verify = new \Think\Verify();
	    $check = $verify->check($code, $id);

	    if (!$check) {
	    	$this->error('注册信息或者验证码错误');
	    }
	}

 //    public function code(){

 //    	$config =    array(
 //    		'imageW' => 100,
 //    		'imageH' => 40,
	//         'fontSize'    =>    20,    // 验证码字体大小
	//         'length'      =>    3,     // 验证码位数
	//         'useNoise'    =>    false, // 关闭验证码杂点
	// 		);
	//     $Verify =  new \Think\Verify($config);
	//     $Verify->entry();

 //    }

	// public function check_ajax(){

	// 	if (IS_POST) {
			
	// 		$username = I('post.username');
	// 		$user = M('user');
	// 		$sql = "SELECT * FROM `user` WHERE `username` = '$username'";

	// 		if(!$user->query($sql)){
	// 			$data = 1;
	// 			$this->ajaxReturn($data, 'json');
	// 		}	
	// 	}
	
	// }
}


?>